package com.nebula.salary.portal.controller;

import com.nebula.salary.common.result.ServerResponse;
import com.nebula.salary.model.dto.PageDto;
import com.nebula.salary.model.vo.PageResult;
import com.nebula.salary.portal.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 历史工资
 *
 * @author codex
 * @since 2022-02-20
 */
@RestController
@Api(tags = "历史工资")
@RequestMapping("/salary/history")
public class HistoryController {
    
    @Resource
    private ISalaryService salaryService;
    
    @ApiOperation(value = "历史工资", notes = "历史工资")
    @GetMapping("/{year}")
    public ServerResponse<PageResult> historySalary(
            @ApiParam(value = "查询的年份", required = true)
            @PathVariable("year") Integer year,
            @ApiParam(value = "分页查询数据传输类", required = true) PageDto pageDto) {
    
        if (year.equals(-1)) {
            // 查询所有工资
            return salaryService.selectAllByPage(pageDto);
        }
        
        // 根据年份查询
        return salaryService.selectSalaryByYear(year, pageDto);
    }
}
